#ifndef DW_GRAPHICS_MATERIALMANAGER_H
#	define DW_GRAPHICS_MATERIALMANAGER_H

namespace dw {
	namespace graphics {

		class Material;

		//class MaterialManager;

		//EXPIMP_TEMPLATE template class Singleton< MaterialManager >;

		class MaterialManager : public dw::base::Singleton< MaterialManager >
		{
		// Constructors
		public:

			MaterialManager();

			~MaterialManager();

		// Methods
		public:

			/// Get the number of managed materials.
			unsigned getNumMaterials() const { return static_cast< unsigned >(_materials.size()); }

			/// Get a material given its index.
			Material* getMaterial(const unsigned i) const ;

			/// Get a material given its name.
			Material* getMaterial(const std::string& name);



			/// Create a named material. 
			///		If a material with the same name already exists, it return the existing material. 
			Material* createMaterial(const std::string& name);

			/// Add a material.
			void addMaterial(Material*);

			/// Remove a material given its index.
			void removeMaterial(const unsigned i);
			
			/// Remove a material given its name.
			void removeMaterial(const std::string& name);

			/// Remove a material.
			void removeMaterial(const Material* material);

		// Typedefs
		private:

			/** helper typedef for the material container. */
			typedef std::vector< Material* >							MaterialArray;

			/** helper typedef for the material index container. */
			typedef std::map< std::string, unsigned >			MaterialIndexMap;
			
			/** helper typedef for the material container iterator. */
			typedef MaterialArray::iterator MaterialIterator;

			/** helper typedef for the material index container iterator. */
			typedef MaterialIndexMap::iterator MaterialIndexIterator;

		private:

			/** Managed materials array. */
			MaterialArray _materials;

			/** Materials index. */
			MaterialIndexMap _materialsIndex;

		};

	} // namespace graphics
} // namespace dw

#endif // !DW_GRAPHICS_MATERIALMANAGER_H
